import api
from tool.get_log import GetLog

logger = GetLog.get_logger()


class Tool:

    # 1.提取token
    @classmethod
    def common_token(cls, response):
        token = response.json().get('data').get('token')
        # 2.追加请求信息头
        api.headers['Authorization'] = 'Bearer ' + token
        logger.info('正在提取token, 提取后的header为：{}'.format(api.headers))
        print('添加token后的header为：', api.headers)

    # 2.断言
    @classmethod
    def common_assert(cls, response, status_code=1149864690826870784):
        logger.info('正在调用公共的断言方法！ ')
        assert status_code == response.json().get('data').get('id')
        # 4.断言响应信息
        assert 'OK' == response.json().get('message')
